#include "instancewidget.h"
#include <QDebug>

InstanceWidget::InstanceWidget(QDateTime timestamp, quint64 size)
{
    QHBoxLayout *centralLayout = new QHBoxLayout();
    this->setLayout(centralLayout);

    QLabel *dateLabel = new QLabel(tr("Date: "));
    centralLayout->addWidget(dateLabel);
    QLabel *dateValue = new QLabel(timestamp.toString("dd.MM.yyyy"));
    dateValue->setObjectName("valueLabel");
    centralLayout->addWidget(dateValue);

    QLabel *timeLabel = new QLabel(tr("Time: "));
    centralLayout->addWidget(timeLabel);
    QLabel *timeValue = new QLabel(timestamp.toString("hh:mm"));
    timeValue->setObjectName("valueLabel");
    centralLayout->addWidget(timeValue);

    QLabel *sizeLabel = new QLabel(tr("Size: "));
    centralLayout->addWidget(sizeLabel);
    QLabel *sizeValue = new QLabel(QString("%1MB").arg(size/(1024*1024)));
    sizeValue->setObjectName("valueLabel");
    centralLayout->addWidget(sizeValue);

    centralLayout->addStretch(1);

    QPushButton *button = new QPushButton();
    connect(button, SIGNAL(clicked()), this, SLOT(onInstanceDeleteClicked()));
    button->setObjectName("removeButton");
    button->setMinimumSize(16, 16);
    button->setMaximumSize(16, 16);
    centralLayout->addWidget(button, Qt::AlignRight);

    this->timestamp = timestamp;
}

QDateTime InstanceWidget::getTimestamp()
{
    return this->timestamp;
}

void InstanceWidget::onInstanceDeleteClicked()
{
    emit deleteInstance(timestamp);
}
